package jumpingnotes.dao.hibernate;

import java.util.List;

import jumpingnotes.dao.MemberExperienceDao;
import jumpingnotes.model.entity.MemberExperience;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class MemberExperienceHibernateDao extends GenericHibernateDao<MemberExperience> implements MemberExperienceDao
{
	public MemberExperienceHibernateDao()
	{
		super(MemberExperience.class);
	}

	@SuppressWarnings("unchecked")
	public List<MemberExperience> findMemberExperienceByMemberId(final int memberId, final int firstResult,
			final int maxResults)
	{
		return (List<MemberExperience>) getHibernateTemplate().execute(new HibernateCallback()
		{
			public Object doInHibernate(Session session) throws HibernateException
			{
				Query query = session
						.createQuery("select distinct me from MemberExperience me where me.member.memberId=:memberId");
				query.setInteger("memberId", memberId);

				if (firstResult >= 0)
					query.setFirstResult(firstResult);
				if (maxResults > 0)
					query.setMaxResults(maxResults);

				return query.list();
			}
		});
	}
}
